const _function = require("../../utils/functionData.js")
Page({
  data: {
    planData: {
      // goal: "掌握小程序开发",
      // content: "1. 学习基础组件\n2. 掌握页面布局\n3. 实现数据绑定\n4. 完成实战项目",
      // startTime: "2024-03-01",
      // totalDays: 21,
      // completedDays: 14
    },
    playId: null
  },
  onLoad(options) {
    // const id = options.id
    this.setData({
      playId: options.id
    })
    this.getplanDetail()
  },
  // 获取学习计划详情
  getplanDetail() {
    // console.log('选择时间', getApp().globalData.userInfo);
    // const id = getApp().globalData.userInfo.userId
    _function.getplanDetail(this.data.playId, '', this.getplanDetailBack, this)
  },
  getplanDetailBack(res) {
    let dataAll = res.data
    if (dataAll.code == 200) {
      console.log('视频列表', dataAll);
      this.setData({
        planData: dataAll.data
      })
    }
  },
  handleClockIn() {
    if (this.data.planData.completedDays >= this.data.planData.totalDays) return;
    console.log('123', this.data.planData.isClock);
    if (this.data.planData.isClock === 'N') {
      _function.postPlanningClock({id:this.data.playId}, this.postPlanningClockBack, this)
    } else if(this.data.planData.isClock === 'Y'){
      wx.showToast({
        title: '今日已经打卡，请明天再来！',
        icon: 'success',
        duration: 1000
      });
    }

  },
  // 获取学习计划详情
  // getplanDetail() {
  //   // console.log('选择时间', getApp().globalData.userInfo);
  //   // const id = getApp().globalData.userInfo.userId

  // },
  postPlanningClockBack(res) {
    let dataAll = res.data
    if (dataAll.code == 200) {
      // console.log('视频列表', dataAll);
      this.getplanDetail()
      wx.showToast({
        title: '打卡成功！',
        icon: 'success',
        duration: 1000
      });
    }
  },
});